package com.diligreat.action; 

import java.io.UnsupportedEncodingException;
import java.util.List;

import com.diligreat.action.base.BaseAction;
import com.diligreat.domain.Content;
import com.diligreat.service.IndexService;
import com.diligreat.service.StartUpService;



/** 
 * @Author  Bruce
 * @Date 2011-4-4
 * @Comments  
 */
public class IndexAction extends BaseAction{
	private static final long serialVersionUID = -6936781825360866279L;

	private IndexService indexService; 
	
	private List<Content> contentList;
	private String language;

	
	
	private StartUpService startUpService;

	
	private String searchinput;
	
	
	@Override
	public String execute() throws Exception {
		//System.out.println("index.htm");
		
		if(this.language==null)
		{
			if(this.getHttpSession().getAttribute("lang")==null)
			{
				this.getHttpSession().setAttribute("lang", "3");
			}
		}
		else
		{
			this.getHttpSession().setAttribute("lang", this.language);
		}
		
		Long l=Long.parseLong((String) this.getHttpSession().getAttribute("lang"));
		this.contentList=this.indexService.getTenContentList(l);
		//String sessionId = this.getSessionId();
		
		//获得TITLE
		//Cache.getCache().setLang(this.startUpService.getSecStepLang());
		
		return SUCCESS;
	}
	
	public String search()
	{
		Long l=Long.parseLong((String) this.getHttpSession().getAttribute("lang"));
		
		try {
			this.contentList=this.indexService.getSearch(l, new String(this.searchinput.getBytes("ISO8859-1"),"UTF-8"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return SUCCESS;
	}
	
	public String cata()
	{
		Long l=Long.parseLong((String) this.getHttpSession().getAttribute("lang"));
		this.contentList=this.indexService.getSearch(l, this.searchinput);
		return SUCCESS;
	}
	
	//---------------------- getter and setter ----------------------


	public List<Content> getContentList() {
		return contentList;
	}

	public void setIndexService(IndexService indexService) {
		this.indexService = indexService;
	}

	public void setContentList(List<Content> contentList) {
		this.contentList = contentList;
	}

	public StartUpService getStartUpService() {
		return startUpService;
	}

	public void setStartUpService(StartUpService startUpService) {
		this.startUpService = startUpService;
	}




	public String getLanguage() {
		return language;
	}




	public void setLanguage(String language) {
		this.language = language;
	}

	public String getSearchinput() {
		return searchinput;
	}

	public void setSearchinput(String searchinput) {
		this.searchinput = searchinput;
	}

}
 